/**
 * Created by pc on 2017/5/24.
 */
(function($) {
    $.fn.bootstrapValidator.i18n.ips = $.extend($.fn.bootstrapValidator.i18n.ips || {}, {
        'default': '请输入有效的IP地址，可添加多个IP，IP间用英文“;”隔开'
    });

    $.fn.bootstrapValidator.validators.ips = {
        html5Attributes: {
            message: 'message'
        },

        /**
         * Return true if the input value is a IP address.
         *
         * @param {BootstrapValidator} validator The validator plugin instance
         * @param {jQuery} $field Field element
         * @param {Object} options Can consist of the following keys:
         * - ipv4: Enable IPv4 validator, default to true
         * - ipv6: Enable IPv6 validator, default to true
         * - message: The invalid message
         * @returns {Boolean|Object}
         */
        validate: function(validator, $field, options) {
            var value = $field.val();
            if (value === '') {
                return true;
            }

            var Regex = /^((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]);?)+$/;


            return Regex.test(value);
        }
    };
}(window.jQuery));